

#include<reg52.h>

//Define eight switchs
sbit ADDRO = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;	
sbit ADDR3 = P1^3;	
sbit ENLED = P1^4;	

void main()
{	
	unsigned int i = 0;	//Use for software delay
	unsigned char cnt = 0;	//Use for shift control
	ADDRO = 0;
	ADDR1 = 1;
	ADDR2 = 1;	//The Y6 output of U3 turns on the transistor Q16
	ADDR3 = 1;	//Make U3 output normally
	ENLED = 0;  //U3,U4 of 74HC138 total enable
	

	//This part is about LED lighting up from right to left
	/*while(1)
	{
		P0 = ~(0x01 << cnt);	//P0 equals 1 to shift the cnt bit to the right, controlling 8 LEDs  0x01 = 0b00000001
		for(i=0; i<20000; i++);
		cnt++;
		if(cnt >= 8)
		{
			cnt = 0;
		}
		
	}*/
	
	//This part is about LED lighting up from left to right
	while(1)
	{
		P0 = ~(0x80 >> cnt);	//P0 equals 1 to shift the cnt bit to the right, controlling 8 LEDs  0x80 = 0b10000000
		for(i=0; i<20000; i++); // delay the app
		cnt++;
		if(cnt >= 8)
		{
			cnt = 0;
		}
		
	}
	
	
}
